var express = require("express");
var router = express.Router();
var setToken = require('./../../public/util/token_vertify')
 
router.get("/", function(req,res) {
    res.render('admin/login.html')
});


router.post("/", function(req,res, next) {
    let username = req.body.username
    let pwd = req.body.pwd
    if(username == 'admin'  && pwd == 'admin123') {
        setToken.setToken(username, pwd).then(data =>{
            return res.json({token: data})
        })
        return next()
    } else {
        res.json({ret_code : 1, ret_msg : '账号或密码错误'});// 若登录失败，重定向到登录页面
    }
});
 
module.exports = router